package com.example.distributesession.controller;

import com.example.distributesession.controller.vo.ResultVO;
import com.example.distributesession.util.JwtUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    String userName = "root";
    String passWord = "rootroot";

    /**
     * 用户登录
     */
    @RequestMapping("/login")
    public ResultVO login(String username, String password) {
        // 判断：用户名和密码 是否存在且正确
        if (userName.equals(username) && passWord.equals(password)) {
            // 登录成功，返回token
            Map<String, String> jwtMap = new HashMap<>();
            jwtMap.put("username", username);
            return new ResultVO(0, "login success", JwtUtil.createJwt(jwtMap));
        }
        return new ResultVO(1, "login fail");
    }

    @RequestMapping("/biz/querySomething")
    public ResultVO querySomething(String token) {
        System.out.println("执行querySomething");
        return new ResultVO(0, "query success");
    }

    @RequestMapping("/biz/querySomething2")
    public ResultVO querySomething2(HttpServletRequest request) {
        System.out.println("querySomething2");
        return new ResultVO(0, "query success");
    }
}